package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ServprodQuery;
import com.xingkeduo.pojo.table.ServprodTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class ServprodService {
    private static final String NAMESPACE = ServprodTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<ServprodTable, ServprodQuery> dao;

    //查询一条
    public ServprodTable selectById(long id) throws Throwable {
        ServprodTable servprodTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(servprodTable))
            return servprodTable;
        return null;
    }

    //查询多条
    public List<ServprodTable> selectLists(ServprodQuery servprodQuery) throws Throwable {
        List<ServprodTable> servprodTableList = dao.select(NAMESPACE, servprodQuery);
        if (!CommonUtil.isEmpty(servprodTableList))
            return servprodTableList;
        return null;
    }

    //分页查询
    public Page<ServprodTable> selectPageLists(ServprodQuery servprodQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<ServprodTable> servprodTablePage = dao.pageSelect(NAMESPACE,servprodQuery,pageNo,pageSize);
        return servprodTablePage;
    }

    //插入
    public int insert(ServprodTable servprodTable) throws Throwable {
//        servprodTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, servprodTable);
    }

    //更新
    public int update(ServprodTable servprodTable) throws Throwable {
        return dao.update(NAMESPACE, servprodTable);
    }

    //删除
    public int delete(ServprodTable servprodTable) throws Throwable {
        return dao.update(NAMESPACE, servprodTable);
    }
}
